//
//  RecommendController.m
//  History
//
//  Created by 戚荣康 on 16/9/5.
//  Copyright © 2016年 kane. All rights reserved.
//

#import "RecommendController.h"
#import <MessageUI/MessageUI.h>


@interface RecommendController ()<UITableViewDataSource,UITableViewDelegate,MFMessageComposeViewControllerDelegate>
{
    IBOutlet UIView *BGView;
    __weak IBOutlet UIView *navView;
    __weak IBOutlet UILabel *titleLbl;
    __weak IBOutlet UITableView *recommendTable;
    __weak IBOutlet UILabel *lineLbl;
    
    
    
    
}
@end

@implementation RecommendController

- (void)viewDidLoad {
    [super viewDidLoad];
    navView.backgroundColor = KKColor_DarkGray_White;
    titleLbl.textColor = KKColor_Black_LightGary;
    lineLbl.backgroundColor = KKColor_NavLineColor;
    recommendTable.backgroundColor = KKColor_DarkWhite_Black;
    
    BGView.backgroundColor = KKColor_BGColor_GrayToDarkgray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)backPress:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark UITableViewDelegate & datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identify = [NSString stringWithFormat:@"%ld%ld",(long)indexPath.section,(long)indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
    }
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.backgroundColor = KKColor_DarkGray_White;
    cell.textLabel.textColor = KKColor_Black_LightGary;
    switch (indexPath.row) {
        case 0:
            cell.imageView.image = [UIImage imageNamed:@"share_message"];
            cell.textLabel.text = @"短信";
            break;
        case 1:
            cell.imageView.image = [UIImage imageNamed:@"share_mail"];
            cell.textLabel.text = @"邮件";
            break;
        case 2:
            cell.imageView.image = [UIImage imageNamed:@"share_wechat"];
            cell.textLabel.text = @"微信好友";
            break;
        case 3:
            cell.imageView.image = [UIImage imageNamed:@"share_pyq"];
            cell.textLabel.text = @"微信朋友圈";
            break;
        case 4:
            cell.imageView.image = [UIImage imageNamed:@"share_weibo"];
            cell.textLabel.text = @"新浪微博";
            break;
        case 5:
            cell.imageView.image = [UIImage imageNamed:@"share_qq"];
            cell.textLabel.text = @"QQ好友";
            break;
            
        default:
            break;
    }
    return cell;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
//            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://"]];
            [self showMessageView:[NSArray arrayWithObjects:nil] title:@"" body:@"我正在使用【一点资讯】，推荐给你，聪明的随身资讯助手，每天只读符合你口味的精华资讯！免费下载http://www.yidianzixun.com/download"];
            break;
        case 1:
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://"]];
            break;
        case 2:
//            [WXApiRequestHandler sendText:@"此处传app iTunes地址" InScene:WXSceneSession];
            break;
        case 3:
//            [WXApiRequestHandler sendText:@"此处传app iTunes地址" InScene:WXSceneTimeline];
            break;
        case 4:

            break;
        case 5:

            break;
            
        default:
            break;
    }

}

#pragma mark - MFMessageComposeViewControllerDelegate
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    [self dismissViewControllerAnimated:YES completion:nil];
    switch (result) {
        case MessageComposeResultSent:
            //信息传送成功
            
            break;
        case MessageComposeResultFailed:
            //信息传送失败
            
            break;
        case MessageComposeResultCancelled:
            //信息被用户取消传送
            
            break;
        default:
            break;
    }
}

-(void)showMessageView:(NSArray *)phones title:(NSString *)title body:(NSString *)body
{
    if( [MFMessageComposeViewController canSendText] )
    {
        MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
        controller.recipients = phones;
        controller.navigationBar.tintColor = [UIColor redColor];
        controller.body = body;
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:YES completion:nil];
        [[[[controller viewControllers] lastObject] navigationItem] setTitle:title];//修改短信界面标题
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息"
                                                        message:@"该设备不支持短信功能"
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil, nil];
        [alert show];
    }
}

@end
